package Gantry::Samples::SOAP;

use strict;
use warnings;

# Inherit from Gantry::Samples, if you need to access its data models, etc.
# Otherwise, this module is completely self standing, except that you need
# to serve it with the stand alone server or deploy it with CGI or mod_perl.

use Gantry qw{
    -PluginNamespace=Gantry::Samples::SOAP
    SOAP::Doc
};

our @ISA = ( 'Gantry' );

sub namespace {
    return 'Gantry::Samples::SOAP';
}

#-----------------------------------------------------------------
# $self->do_f2c(  )
#-----------------------------------------------------------------
sub do_f2c {
    my ( $self ) = @_;
    my $time     = $self->soap_current_time();
    my $params   = $self->params();  # easy way

    my $f_temp   = $params->{ farenheit };
    my $celcius  = 5.0 * ( $f_temp - 32 ) / 9.0;

# hard way:
#    my $xmlobj   = XML::LibXML->new();
#    my $dom      = $xmlobj->parse_string( $self->get_post_body() )
#            or return return_error( "Mal-formed XML request: $!" );
#
#    my ( $f_node ) = $dom->getElementsByLocalName( 'farenheit' );
#    my $f_temp     = $f_node->textContent;

    my $ret_struct = [
        {
            GantrySoapServiceResponse => [
                { currentUTCTime => $time },
                { celcius        => $celcius },
            ]
        }
    ];

    $self->soap_namespace_set(
        'http://usegantry.org/soapservice'
    );

    return $self->soap_out( $ret_struct, 'internal', 'pretty' );
} # END do_f2c

1;

=head1 NAME

Gantry::Samples::SOAP - A controller in the Gantry::Samples application

=head1 SYNOPSIS

This package is meant to be used in a stand alone server/CGI script or the
Perl block of an httpd.conf file.

Stand Alone Server or CGI script:

    use Gantry::Samples::SOAP;

    my $cgi = Gantry::Engine::CGI->new( {
        config => {
            #...
        },
        locations => {
            '/someurl' => 'Gantry::Samples::SOAP',
            #...
        },
    } );

httpd.conf:

    <Perl>
        # ...
        use Gantry::Samples::SOAP;
    </Perl>

    <Location /someurl>
        SetHandler  perl-script
        PerlHandler Gantry::Samples::SOAP
    </Location>

If all went well, one of these was correctly written during app generation.

=head1 DESCRIPTION

This module was originally generated by Bigtop.  But feel free to edit it.
You might even want to describe the table this module controls here.

=head1 METHODS

=over 4

=item do_f2c

=item schema_base_class

=item get_orm_helper


=back


=head1 DEPENDENCIES

    Gantry::Samples
    XML::Simple
    Gantry::Plugins::SOAP::Doc

=head1 AUTHOR

Phil Crow, E<lt>phil@localdomainE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2007 Phil Crow

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.

=cut
